<?php

namespace App\Http\Controllers\Admin;

use App\Models\Fixfxs;
use App\Models\Onorder;
use App\Models\Sjorder;
use App\Models\Store;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class OnbespeakorderController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */

    public function __construct()
    {
        view()->share([
            '_orders' => 'am-in',
            '_onbespeak' => 'am-active',

        ]);

    }

//私教订单管理首页
    public function index(Request $request)
    {
        $where = function ($query) use ($request) {
            //订单号搜索
            if($request->has('order_no')and $request->order_no !=''){
                $search = "%".$request->order_no."%";
                $query->where('order_no','like',$search);
            }
           //客户电话搜索
            if($request->has('oncustomer_tel')and $request->oncustomer_tel !=''){
                $search = "%".$request->oncustomer_tel."%";
                $query->where('oncustomer_tel','like',$search);
            }
           //客户姓名搜索
            if($request->has('oncustomer_name')and $request->oncustomer_name !=''){
                $search = "%".$request->oncustomer_name."%";
                $query->where('oncustomer_name','like',$search);
            }
            //门店搜索
            if($request->has('store_id')and $request->store_id !='-1'){

                $query->where('store_id',$request->store_id);
            }



        };
           //所有门店
        $cates=Store::all();
           //订单关联私教项目，私教规格，门店，教练，客户
             $sjs=Sjorder::where($where)->where('is_pay',1)->with('bespeakcate')->with('bespeak')->with('store')->with('fixfxs')->with('oncustomer')
                 ->orderBy('created_at','desc')->paginate(20);
                 return view('admin.order.onbespeakorder',compact('sjs','cates'));
    }

    //Ajax改变状态
    public function change_attr(Request $request)
    {

        $order = Onorder::find($request->id);

        if ($order->statu == 0) {
            $data['statu'] = 1;
            $order->update($data);
        }
    }
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
